home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 147_01 / mainop.c < prev    next >
Text File  |  1985-03-09  |  8KB  |  354 lines

  1. /***************************************************************
  2. * MAINOP.C
  3.  
  4. Release 7: RBBS 4.1 Edit 02 - Added check to allow display only
  5.                   if message is not deleted for
  6.                   continuous display with "+" or "*".
  7.                 - Skips Confirm message if any typeahead
  8.                   after G command.
  9.                 - Added test for % in gocpm.
  10. Release 6: RBBS 4.1 Edit 01 - Fixed msgno display in killmsg
  11.                 - Relaxed permissions for non-PERSONAL mail
  12. Release 5: RBBS 4.1 Edit 00 - Names now one large field
  13.                 - Activated lstmsg for 1st 7 non-PERSONALs
  14.                 - Inserted NOSITE into showuser
  15.                 - Inserted PERSONLY in readmsgs
  16. Release 4: RBBS 4.0 Edit 21 - fixed restricted-user bug in gocpm
  17. Release 1: RBBS 4.0 Edit 18
  18.  
  19. * This file includes the functions:
  20.  
  21. * readmsgs    calls tstnum, readmsg, tstaddr, prnt_sum, and
  22.                 readtxt if OK.
  23.  
  24. * summsgs    calls tstnum, readsum, tstaddr, and dispsum if OK
  25.  
  26. * killmsg    calls tstnum, readsum, tstaddr, dispsum, and
  27.                 ritesum if OK to delete
  28.  
  29. * goodbye    calls closing and hexit to hangup
  30.  
  31. * gocpm        calls closing and rexit
  32.  
  33. * tos        time in RBBS
  34.  
  35. * chgpasswd    calls chkpwd and updtuser
  36.  
  37. * help        calls bufinmsg to display HELP.CCC
  38.  
  39. * bulletins    calls bufinmsg to display BULLETINS.CCC
  40.  
  41. * showuser    called by maindispatch U command
  42.  
  43. * tstnum    prompts for msgno, checks for pause/quit
  44.  
  45. * tstaddr    checks to see if user is "authorized" to see the
  46.                 particular msg selected.
  47.  
  48. *****************************************************************/
  49.  
  50. #include    <bdscio.h>
  51. #include    "rbbs4.h"
  52.  
  53. int    skipquit;
  54. int    plus;
  55. /***************************************************************/
  56. readmsgs(fd,u,s)
  57. int    fd;
  58. struct    _user    *u;
  59. struct    _sum    *s;
  60. {
  61.     int    i;
  62.     int    flag;
  63.  
  64.     if ( !(i = tstnum("read",u)) )
  65.         return;
  66.     do
  67.     {
  68.         readsum(fd,mndx[i++],s);
  69.         flag = TRUE;
  70.         if ( personal )
  71.             flag = tstaddr(u,s,FALSE);
  72.         if ( flag && mno[i-1])
  73.         {
  74.             crlf(1);
  75. #if    !PERSONLY
  76.             if ( cchoice && (mno[i-1] > u->lstmsg[cchoice-1]) )
  77.                 u->lstmsg[cchoice-1] = mno[i-1];
  78. #endif
  79.             prnt_sum(s);
  80.             crlf(1);
  81.             readtxt(fd,mndx[i-1],s);
  82.             if (!skipquit)
  83.                 if ( (i <= msgct) && plus)
  84.                 if (!getyn("More"))
  85.                     i = msgct + 2;
  86.         }
  87.     } while ( (i <= msgct) && plus);
  88.     plus = FALSE;
  89. }
  90. /***************************************************************/
  91. summsgs(fd,u,s)
  92. int    fd;
  93. struct    _user    *u;
  94. struct    _sum    *s;
  95. {
  96.     int    i;
  97.     int    fftflg;
  98.     int    flag;
  99.  
  100.     if ( !(i = tstnum("summarize",u)))
  101.         return;
  102.     fftflg = TRUE;
  103.     do
  104.     {
  105.         readsum(fd,mndx[i++],s);
  106.         flag = TRUE;
  107.         if ( personal )
  108.             flag = tstaddr(u,s,FALSE);
  109.         if ( flag && mno[i-1])
  110.         {
  111.             if (fftflg && !expert)
  112.             {
  113. outstr(" No. Ct.    Date    From       -> To          Subject",2);
  114.                 crlf(1);
  115.                 fftflg = FALSE;
  116.             }
  117.             dispsum(s);
  118.             if (!(i%22))
  119.             {
  120.                 if (!skipquit)
  121.                     if ( (i <= msgct) && plus)
  122.                         if (!getyn("More"))
  123.                             return FALSE;
  124.             }
  125.         }
  126.     } while ( (i <= msgct) && plus);
  127.     plus = FALSE;
  128. }
  129. /***************************************************************/
  130. killmsg(fd,u,s)
  131. int    fd;
  132. struct    _user    *u;
  133. struct    _sum    *s;
  134. {
  135.     int    i;
  136.  
  137.     if ( !(i = tstnum("kill",u)))
  138.         return;
  139.     do
  140.     {
  141.         readsum(fd,mndx[i],s);
  142.         if (tstaddr(u,s,TRUE) && mno[i])
  143.         {
  144.             dispsum(s);
  145.             crlf(1);
  146.             if (getyn("Delete it"))
  147.             {
  148.                 s->mstat = FALSE;
  149.                 ritesum(fd,mndx[i],s);
  150.                 mno[i] = FALSE;
  151.             }
  152.         }
  153.         else
  154.         {
  155.             outstr("You are not authorized to kill message #",3);
  156.             sprintf(tmpstr,"%d",mno[i]);
  157.             outstr(tmpstr,1);
  158.             crlf(1);
  159.         }
  160.         ++i;
  161.     } while ( (i <= msgct) && plus);
  162.     plus = FALSE;
  163. }
  164. /***************************************************************/
  165. goodbye(fd,ufd,u,s)
  166. int    fd,ufd;
  167. struct    _user    *u;
  168. struct    _sum    *s;
  169. {
  170.     if (!*sav)
  171.         if ( !getyn("Confirm") )
  172.             return fd;
  173.     if (fd = closing(fd,ufd,u,s))
  174.         return fd;
  175. #if    DATETIME
  176.     tos();
  177. #endif
  178. #if    HANGUP
  179.     sprintf(tmpstr,"Goodbye %s.  Please call again!",u->nm);
  180.     outstr(tmpstr,2);
  181. #else
  182.     outstr("Returning to CP/M...",2);
  183. #endif
  184.     hexit();        /* Hangup    */
  185. }
  186. /***************************************************************/
  187. gocpm(fd,ufd,u,s)
  188. int    fd,ufd;
  189. struct    _user    *u;
  190. struct    _sum    *s;
  191. {
  192.     if ( (*(u->ustat) == '*') || (*(u->ustat) == '%') )
  193.     {
  194.         outstr("Access to CP/M has been denied.",2);
  195.         return fd;
  196.     }
  197.     if (fd = closing(fd,ufd,u,s))
  198.         return fd;
  199. #if    DATETIME
  200.     tos();
  201. #endif
  202.     if (!expert)
  203.         bufinmsg("EXIT2CPM");
  204.     rexit();
  205. }
  206. /***************************************************************/
  207. #if    DATETIME
  208. tos()
  209. {
  210.     char    dif[9];
  211.  
  212.     strcpy(dif,"00:00:00");
  213.     get_date();
  214.     sscanf(logdate+10,"%s ",tmpstr);
  215.     sscanf(sysdate+10,"%s ",tmpstr+10);
  216.     timdif(tmpstr,tmpstr+10,dif);
  217.     sprintf(tmpstr,"Time in RBBS: %s",dif);
  218.     outstr(tmpstr,1);
  219. }
  220. #endif
  221. /***************************************************************/
  222. chgpasswd(u,fd)
  223. struct    _user    *u;
  224. int    fd;
  225. {
  226.     chkpwd(u->pwd);
  227.     updtuser(u,fd);
  228. }
  229. /***************************************************************/
  230. help() 
  231. {
  232.     bufinmsg("HELP");
  233. }
  234. /***************************************************************/
  235. bulletins()
  236. {
  237.     if (bufinmsg("BULLETINS"));
  238.     else
  239.         outstr("NO BULLETINS",2);
  240. }
  241. /****************************************************************/
  242. showuser(fd,u)        /*CHECKS THE USER FILE & EXITS    */
  243. int    fd;            
  244. struct    _user    *u;
  245. {
  246.     int    ndx;
  247.     struct    _user    u2;
  248.     char    temp[SECSIZ];
  249.  
  250.     for ( ndx = 1; ndx <= u->maxno; ndx++)
  251.     {
  252.         /* SPRINT CONSTANT INFORMATION */
  253.         formrec(tmpstr,SECSIZ);
  254.         readrec(fd,ndx,tmpstr,1);
  255.         sscanf(tmpstr+NM,"%s",u2.nm);        /* NM:    */
  256. #if    (NOSITE && LASTREAD)
  257. #else
  258.         sscanf(tmpstr+FRM,"%s",u2.from);    /* FRM:    */
  259. #endif
  260.         sscanf(tmpstr+LLG,"%s",u2.lastlog);    /* LLG:    */
  261.         sprintf(temp,"%-16s  Last Logon: %s",u2.nm,u2.lastlog);
  262. #if    (NOSITE && LASTREAD)
  263. #else
  264. #if    DATETIME
  265.         sprintf(tmpstr,"  from %-20s",u2.from);
  266. #else
  267.         sprintf(tmpstr,"  from %s",u2.from);
  268. #endif
  269.         strcat(temp,tmpstr);
  270. #endif
  271.         outstr(temp,1);
  272.         if (!(ndx%22))
  273.             if(!getyn("More"))
  274.                 ndx = u->maxno+1;
  275.     }
  276. }
  277. /****************************************************************/
  278. tstnum(msg,u)
  279. char    *msg;
  280. struct    _user    *u;
  281. {
  282.     char        input[6];
  283.     int        i,n;
  284.     unsigned    *addr;
  285.  
  286.     outstr("Message Number: ",5);
  287.     instr("",input,6);
  288.     crlf(2);
  289.     addr = input + strlen(input)-1;
  290.     plus = FALSE;
  291.     if (*addr == '+' || *addr == '*')
  292.     {
  293.         skipquit = FALSE;
  294.         if(*addr == '*')
  295.             skipquit = TRUE;
  296.         plus = TRUE;    
  297.         *addr = 0;
  298.     }
  299.     if (!strcmp("summarize",msg))
  300.         plus = TRUE;
  301.     if ( cchoice && (*input == '#') )
  302.         n = u->lstmsg[cchoice-1] + 1;
  303.     else
  304.         n = atoi(input);
  305.     if (n > lastmsg)
  306.     {
  307.         outstr("Message no. out of range",1);
  308.         return FALSE;
  309.     }
  310.         i = 1;
  311.     while (i <= msgct)
  312.     {
  313.         if (mno[i++] == n)
  314.             return --i;
  315.         if (i > msgct)
  316.         {
  317.             if (plus)
  318.             {
  319.                 ++n;
  320.                 i = 1;
  321.                 if (n > lastmsg)
  322.                     return FALSE;
  323.             }
  324.             else
  325.                 return FALSE;
  326.         }
  327.     }
  328. }
  329. /****************************************************************/
  330. /* Checks to see if the user is authorized             */
  331. /* to see the message and returns FALSE if not            */
  332.  
  333. tstaddr(u,s,type)
  334. struct    _user    *u;
  335. struct    _sum    *s;
  336. int    type;
  337. {
  338.     capstr(s->tnm);
  339.     capstr(s->fnm);
  340.     if (!s->mstat)
  341.         return FALSE;
  342.     if ( (sysop) || (!strcmp("ALL",s->tnm) && !type) )
  343.         return TRUE;
  344.     if ( !strcmp(u->nm,s->tnm) )
  345.         return TRUE;
  346.     if ( !strcmp(u->nm,s->fnm) )
  347.         return TRUE;
  348.     return FALSE;
  349. }
  350. /****************************************************************/
  351.     }
  352.     if (!strcmp("summarize",msg))
  353.         plus = TRUE;
  354.     if ( cch